Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang][NFC] Add CWG713 test; add example from CWG1584 test #100747

Merged
merged 4 commits into from
Aug 5, 2024

Conversation

MitalAshok
Copy link
Contributor

@MitalAshok MitalAshok requested a review from Endilll as a code owner July 26, 2024 13:56
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Jul 26, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jul 26, 2024

@llvm/pr-subscribers-clang

Author: Mital Ashok (MitalAshok)

Changes

https://cplusplus.github.io/CWG/issues/713.html
https://cplusplus.github.io/CWG/issues/1584.html


Full diff: https://github.com/llvm/llvm-project/pull/100747.diff

3 Files Affected:

  • (modified) clang/test/CXX/drs/cwg15xx.cpp (+31-17)
  • (modified) clang/test/CXX/drs/cwg7xx.cpp (+17-1)
  • (modified) clang/www/cxx_dr_status.html (+1-1)
diff --git a/clang/test/CXX/drs/cwg15xx.cpp b/clang/test/CXX/drs/cwg15xx.cpp
index 21a392a5141e3..961c25000111a 100644
--- a/clang/test/CXX/drs/cwg15xx.cpp
+++ b/clang/test/CXX/drs/cwg15xx.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify=expected,cxx98 -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify=expected,cxx11-20,since-cxx11,cxx11-14 -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify=expected,cxx11-20,since-cxx11,cxx11-14,cxx14-17 -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify=expected,cxx11-20,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors
@@ -6,6 +6,11 @@
 // RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx23,since-cxx20,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify=expected,since-cxx23,since-cxx20,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors
 
+#if __cplusplus == 199711L
+#define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
+// cxx98-error@-1 {{variadic macros are a C99 feature}}
+#endif
+
 namespace cwg1512 { // cwg1512: 4
   void f(char *p) {
     if (p > 0) {}
@@ -556,24 +561,33 @@ auto CWG1579_lambda_invalid = []() -> GenericMoveOnly<char> {
 } // end namespace cwg1579
 
 namespace cwg1584 { // cwg1584: 7 drafting 2015-05
-#if __cplusplus >= 201103L
-  // Deducing function types from cv-qualified types
-  template<typename T> void f(const T *); // #cwg1584-f
-  template<typename T> void g(T *, const T * = 0);
-  template<typename T> void h(T *) { T::error; }
-  // since-cxx11-error@-1 {{type 'void ()' cannot be used prior to '::' because it has no members}}
-  //   since-cxx11-note@#cwg1584-h {{in instantiation of function template specialization 'cwg1584::h<void ()>' requested here}}
-  template<typename T> void h(const T *);
-  void i() {
-    f(&i);
-    // since-cxx11-error@-1 {{no matching function for call to 'f'}}
-    //   since-cxx11-note@#cwg1584-f {{candidate template ignored: could not match 'const T *' against 'void (*)()'}}
-    g(&i);
-    h(&i); // #cwg1584-h
-  }
-#endif
+// Deducing function types from cv-qualified types
+template<typename T> void f(const T *); // #cwg1584-f
+template<typename T> void g(T *, const T * = 0);
+template<typename T> void h(T *) { T::error; }
+// expected-error@-1 {{type 'void ()' cannot be used prior to '::' because it has no members}}
+//   expected-note@#cwg1584-h {{in instantiation of function template specialization 'cwg1584::h<void ()>' requested here}}
+template<typename T> void h(const T *);
+void i() {
+  f(&i);
+  // expected-error@-1 {{no matching function for call to 'f'}}
+  //   expected-note@#cwg1584-f {{candidate template ignored: could not match 'const T *' against 'void (*)()'}}
+  g(&i);
+  h(&i); // #cwg1584-h
 }
 
+template<typename T> struct tuple_size {
+  static const bool is_primary = true;
+};
+template<typename T> struct tuple_size<T const> : tuple_size<T> {
+  static const bool is_primary = false;
+};
+
+tuple_size<void()> t;
+static_assert(tuple_size<void()>::is_primary, "");
+static_assert(tuple_size<void()const>::is_primary, "");
+} // namespace cwg1584
+
 namespace cwg1589 {   // cwg1589: 3.7 c++11
 #if __cplusplus >= 201103L
   // Ambiguous ranking of list-initialization sequences
diff --git a/clang/test/CXX/drs/cwg7xx.cpp b/clang/test/CXX/drs/cwg7xx.cpp
index 6d93e2948dadb..1e5d3c0873d8b 100644
--- a/clang/test/CXX/drs/cwg7xx.cpp
+++ b/clang/test/CXX/drs/cwg7xx.cpp
@@ -1,9 +1,14 @@
-// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++98 %s -verify=expected,cxx98-14,cxx98-11 -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++98 %s -verify=expected,cxx98,cxx98-14,cxx98-11 -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++11 %s -verify=expected,cxx98-14,cxx98-11,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++14 %s -verify=expected,cxx98-14,since-cxx14,since-cxx11,cxx14 -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++17 %s -verify=expected,since-cxx14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++2a %s -verify=expected,since-cxx14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
 
+#if __cplusplus == 199711L
+#define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
+// cxx98-error@-1 {{variadic macros are a C99 feature}}
+#endif
+
 namespace cwg705 { // cwg705: yes
   namespace N {
     struct S {};
@@ -71,6 +76,17 @@ namespace cwg712 { // cwg712: partial
 #endif
 }
 
+namespace cwg713 { // cwg713: yes
+static_assert(!__is_const(void()const), "");
+static_assert(!__is_const(void()const volatile), "");
+static_assert(!__is_volatile(void()volatile), "");
+static_assert(!__is_volatile(void()const volatile), "");
+#if __cplusplus >= 201103L
+static_assert(!__is_const(void()const&), "");
+static_assert(!__is_volatile(void()volatile&), "");
+#endif
+} // namespace cwg713
+
 namespace cwg727 { // cwg727: partial
   struct A {
     template<typename T> struct C; // #cwg727-C
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 937f67981e296..3dd91be9ed9d3 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -4327,7 +4327,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
     <td><a href="https://cplusplus.github.io/CWG/issues/713.html">713</a></td>
     <td>CD2</td>
     <td>Unclear note about cv-qualified function types</td>
-    <td class="unknown" align="center">Unknown</td>
+    <td class="full" align="center">Yes</td>
   </tr>
   <tr id="714">
     <td><a href="https://cplusplus.github.io/CWG/issues/714.html">714</a></td>

@MitalAshok
Copy link
Contributor Author

@Endilll The problem with the CWG713 test in Clang 18 was with parsing the type trait (#81298), they weren't actually considered const: https://godbolt.org/z/snde76brE

Also, I would think since the resolution is purely editorial (it just changes notes, nothing normative), it would be considered implemented in any clang version?

@Endilll
Copy link
Contributor

Endilll commented Jul 26, 2024

Also, I would think since the resolution is purely editorial (it just changes notes, nothing normative), it would be considered implemented in any clang version?

The question "availability" answers is "What is the first Clang version that exhibits the correct behavior?", where the correct behavior is approximated by the test in our test suite. Because Clang 18 does not pass your CWG713 test, we can't claim that it implements this CWG issue as we understand it.

@@ -71,6 +76,17 @@ namespace cwg712 { // cwg712: partial
#endif
}

namespace cwg713 { // cwg713: yes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check how just released Clang 19.1-rc1 handles this test, and choose between 19 and 20 accordingly.

@MitalAshok
Copy link
Contributor Author

New test compiles down to clang 3.0 (except warnings for https://cplusplus.github.io/CWG/issues/547.html) but do not compile before that because of the lack of __is_const/__is_volatile type traits.

Function types with cv- qualifiers were added for Clang 2.5 in 22c40fa, where they already used a different field to hold the qualifiers (thus the function types were not considered const/volatile/__restrict themselves), so it should be okay to claim this was implemented in Clang 2.5?

@Endilll
Copy link
Contributor

Endilll commented Jul 26, 2024

New test compiles down to clang 3.0 (except warnings for https://cplusplus.github.io/CWG/issues/547.html) but do not compile before that because of the lack of __is_const/__is_volatile type traits.

Function types with cv- qualifiers were added for Clang 2.5 in 22c40fa, where they already used a different field to hold the qualifiers (thus the function types were not considered const/volatile/__restrict themselves), so it should be okay to claim this was implemented in Clang 2.5?

Thank you for the analysis! Typically you don't need to dig that deep. Based on https://godbolt.org/z/n6oPdMT91, I think 3.1 is the correct availability here, but I can be persuaded for 3.0.

Clang 2.7 was the first one that by default provided C++ support without relying on GCC frontend, so I don't think it's meaningful to go further than that. (Clang 2.6 (assertions) on Compiler Explorer is patched to use internal C++ support, you can see for yourself how broken it was.)

@MitalAshok
Copy link
Contributor Author

Based on https://godbolt.org/z/n6oPdMT91, I think 3.1 is the correct availability here, but I can be persuaded for 3.0.

The warnings are because of how the test is written, the tested behaviour ("function types are never const or volatile") is still true in Clang 3.0

@MitalAshok MitalAshok changed the title [clang][Tests][NFC] Add CWG713 test; add example from CWG1584 test [clang][NFC] Add CWG713 test; add example from CWG1584 test Jul 31, 2024
@cor3ntin cor3ntin merged commit 30e5d71 into llvm:main Aug 5, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants